package chapter;

public class object_enum {
    public static void main(String[] args) {
        System.out.println(City.BEIJING.name );
        System.out.println(City.SHANGHAI.code);
        System.out.println(MyCity.BEIJING);
    }
}
//枚举是一个特殊的类，其中包含特定的对象且不会发生改变，一般用大写的标识符
//枚举类不会创建对象，都是在内部生成的
class MyCity {
    public String name;
    public int code;
    private  MyCity(String name, int code) {
        //TODO private只能在内部创建
        this.name = name;
        this.code = code;
    }
    public static final MyCity BEIJING = new MyCity("BEIJING", 0);
    public static final MyCity SHANGHAI = new MyCity("SHANGHAI", 1);
    //TODO 用static可以不用创建对象就能访问，final使其无法修改
}
enum City {
    BEIJING("北京",1),SHANGHAI("上海",2);
    City(String name,int code) {
        this.name = name;
        this.code = code;
    }
    public String name;
    public int code;
}